import { AccountType, RoleType, UserInfoType } from "@/types/user";
import request from "@/utils/request";
//登录
export const userLogin = (user: AccountType) => {
  return request.post("login", user);
};
// 账号列表
export const userGet = () => {
  return request.get("users", {
    params: {
      where: { roleId: { $exists: true } },
    },
  });
};

// 注册
export const userReg = (user: AccountType) => {
  return request.post("users", user);
};

// 更新

export const userUpdate = (
  id: string,
  token: string,
  user: Pick<UserInfoType, "nickname" | "avatar">
) => {
  return request.put(`users/${id}`, user, {
    headers: {
      "X-LC-Session": token,
    },
  });
};

// 角色新增
export const rolePost = (roleObj: RoleType) => {
  return request.post("classes/ReactRole", roleObj);
};

// 角色列表
export const roleGet = (id?: string) => {
  let param = id ? `/${id}` : "";
  return request.get(`classes/ReactRole${param}`);
};

//批量删除角色
export const roleBatchDel = (ids: React.Key[]) => {
  let requests = ids.map((id) => {
    return {
      method: "DELETE",
      path: `/1.1/classes/ReactRole/${id}`,
    };
  });
  return request.post("batch", { requests });
};
